namespace System
{
    public static class DateTimeExtensions
    {
        /// <summary>
        /// Toes the UTC time since string.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static string ToUtcTimeSinceString(this DateTime date)
        {
            return (DateTime.UtcNow - date).ToLongString(date);
        }

        /// <summary>
        /// Toes the time since string.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static string ToTimeSinceString(this DateTime date)
        {
            return (DateTime.Now - date).ToLongString(date);
        }

        /// <summary>
        /// Returns time span in a long string format.
        /// </summary>
        /// <param name="time">The time.</param>
        /// <returns></returns>
        public static string ToLongString(this TimeSpan time, DateTime theDate)
        {
            string output = String.Empty;

            if (time.Days > 30)
            {
                DateTime Today = DateTime.Now;
                TimeSpan Span = Today - theDate;

                DateTime age = DateTime.MinValue + Span;

                int years = age.Year - 1;
                int months = age.Month - 1;
                int days = age.Day - 1;
                if (years>0)
                    output += years.ToString() + " years ";
                if (months > 0)
                    output += months.ToString() + " months ";
                if (days > 0)
                    output += days.ToString() + " days";

                return output.Trim();

            }
            if (time.Days > 0)
                output += time.Days + " days ";

            if ((time.Days == 0 || time.Days == 1) && time.Hours > 0)
                output += time.Hours + " hr ";

            if (time.Days == 0 && time.Minutes > 0)
                output += time.Minutes + " min ";

            if (output.Length == 0)
                output += time.Seconds + " sec";

            return output.Trim();
        }
    }
}